﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Security.Cryptography;


public partial class Reg : System.Web.UI.Page
{
    PM.Model.Sys_Account ateacher = new PM.Model.Sys_Account();
    PM.PMSys.account aaccount = new PM.PMSys.account();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //绑定学院列表
            try
            {
                PM.Code.Web.controlbind.BindDropDownList(ddlDepart, "select collegename from Dict_College", "collegename", "collegename");
                ddlDepart.Items.Insert(0, "");
            }
            catch (System.Exception ex)
            {
                PM.Code.Web.alertmessage.ShowMsg("发生错误,错误原因:" + ex.ToString());
            }
        }

    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            int i;
            i = aaccount.CheckUser(txtTid.Value.ToString().Trim());
            if (i == 1)
            {
                PM.Code.Web.alertmessage.ShowMsg("该职工号已被注册，请联系管理员核查！");
                txtTid.Focus();
            }
            else
            {
                try
                {
                    if (rbUsertype1.Checked)
                    {
                        ateacher.usertype = 1;
                    }
                    else if (rbUsertype2.Checked)
                    {
                        ateacher.usertype = 2;
                    }
                    else
                    {
                        ateacher.usertype = 3;
                    }
                    ateacher.tid = txtTid.Value.ToString().Trim();
                    string salt = PM.Code.Web.safety.get_GenerateSalt();//密码加密权值
                    ateacher.salt = salt;
                    if (txtPwd.Value == txtPwd2.Value)
                    {
                        ateacher.pwd = PM.Code.Web.safety.EncodePassword(txtPwd.Value.ToString().Trim(), salt);
                    }
                    ateacher.name = txtName.Value.ToString().Trim();
                    if (rbSexmale.Checked)
                    {
                        ateacher.sex = "男";
                    }
                    else
                    {
                        ateacher.sex = "女";
                    }
                    ateacher.depart = ddlDepart.SelectedValue.ToString();
                    ateacher.field = txtField.Value.ToString().Trim();
                    ateacher.bg = sltBg.Value.ToString();
                    ateacher.title = sltTitle.Value.ToString();
                    ateacher.telephone = txtTelephone.Value.ToString().Trim();
                    ateacher.cellphone = txtCellphone.Value.ToString().Trim();
                    ateacher.email = txtEmail.Value.ToString().Trim();
                    ateacher.intro = txtIntro.Text.ToString().Trim();
                    ateacher.status = 0;//默认状态为未通过审核状态(1通过0未通过)
                    ateacher.regdatetime = DateTime.Parse(DateTime.Now.ToString());
                    if (aaccount.Add(ateacher) > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("您的账户已经建立，登录账户为：{0}   登录密码为：{1}  ", ateacher.tid, ateacher.pwd);
                        sb.Append("请耐心等待管理员审核通过。");
                        //PM.Code.Web.alertmessage.ShowEUIMsg(this.Page, "注册成功", sb.ToString(), "提示");
                        PM.Code.Web.alertmessage.ShowMsg(sb.ToString(), "Index.aspx");
                    }
                    else
                    {
                        PM.Code.Web.alertmessage.ShowMsg("注册失败，请重新尝试注册或与管理员联系!");
                    }
                }
                catch (System.Exception ex)
                {
                    PM.Code.Web.alertmessage.ShowMsg("发生错误,错误原因:" + ex.ToString());
                }
            }
        }
    }
}
